﻿package{
	
	
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.Event;

	import flash.media.Sound;
	import flash.media.SoundChannel;
	
	public class Menu_Title extends Sprite{
		
		
		private var snd_BGM_UI:SoundChannel;
		
		
		public function Menu_Title(){
			
			
			
			addEventListener(Event.ADDED_TO_STAGE, Init);
			
		}
		
		private function Init(e:Event) {
			removeEventListener(Event.ADDED_TO_STAGE, Init);
			
			//각 메뉴 버튼을 눌렀을 때 실행할 리스너 등록
			PointC.addEventListener(MouseEvent.CLICK, onClick);
			Help.addEventListener(MouseEvent.CLICK, onClick);
			Record.addEventListener(MouseEvent.CLICK, onClick);
			GetClickr.addEventListener(MouseEvent.CLICK, onClick);
			
			
			var BGM:BGM_UI = new BGM_UI();
			snd_BGM_UI = BGM.play(0, 999);
			
		}
		
		private function onClick(e:MouseEvent) {
			//이벤트를 발생시킨 객체의 이름에 따라 각 메뉴를 호출하는 이벤트를 발생시킨다. 이는 Clickr에서 청취한다.
			
			switch(e.currentTarget.name){
				case "PointC":
				snd_BGM_UI.stop();
				dispatchEvent(new NavigationEvent(NavigationEvent.START, "PointC"));
				PointC.removeEventListener(MouseEvent.CLICK, onClick);
				break;
				case "Help":
				dispatchEvent(new NavigationEvent(NavigationEvent.SHOW_HELP, null));
				break;
				case "Record":
				dispatchEvent(new NavigationEvent(NavigationEvent.SHOW_RECORD, null));
				break;
				case "GetClickr":
				dispatchEvent(new NavigationEvent(NavigationEvent.SHOW_GETCLICKR, null));
				break;
			}
		}
		
	}
	
	
}